package com.lyf.shop.controller;

import com.lyf.common.core.web.controller.BaseController;
import com.lyf.common.core.web.domain.AjaxResult;
import com.lyf.common.security.annotation.RequiresPermissions;
import com.lyf.shop.domain.IndexQueryFrom;
import com.lyf.shop.service.INumberTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Author: lyf
 * @CreateTime: 2023-04-16
 * @description:
 */

@RestController
@RequestMapping("/total")
public class IndexController extends BaseController {



    @Autowired
    private INumberTotalService  numberTotalService;


    @RequiresPermissions("supermarket:commodity:list")
    @GetMapping("/list")
    public AjaxResult numberTotal(IndexQueryFrom queryFrom){
        System.out.println(queryFrom);
        List<BigDecimal> amountTotal = numberTotalService.amountTotal(queryFrom);
        List<Long> numberTotal = numberTotalService.numberTotal(queryFrom);
        List<IndexQueryFrom> lineAmountTotal = numberTotalService.lineAmountTotal(queryFrom);

        List<BigDecimal> bigDecimals = new ArrayList<>();
        List<String> date = new ArrayList<>();
        List<Long> num = new ArrayList<>();

        Map<String, Object>  amount = new HashMap<>();
        for (IndexQueryFrom line : lineAmountTotal) {

            bigDecimals.add(line.getAmount());
            date.add(line.getDate());
            num.add(line.getNum());
        }
        Collections.reverse(bigDecimals);
        Collections.reverse(date);
        Collections.reverse(num);

        amount.put("bigDecimals",bigDecimals);
            amount.put("date",date);
            amount.put("num",num);
        Map<String, Object>  map = new HashMap<>();
        map.put("amountTotal",amountTotal);
        map.put("numberTotal",numberTotal);
        map.put("lineAmountTotal",amount);




        return success(map);
    }
}
